#!/usr/bin/perl
use Getopt::Std;
#perl perl_create_replacesample_sdrf_tfam.pl -t GBM.tfam -s GBM.sdrf -n GBM_sdrf.tfam
#use strict;
#getopt("d:o", \%args);
my %args;
getopt("t:s:n", \%args);
#sdrf file directory
my $tfamfile = $args{t};
#output combined sdrf file
my $sdrf = $args{s};
my $newtfamfile = $args{n};
chomp($tfamfile);
chomp($sdrf);
chomp($newtfamfile);
open(WRBUFF,">$newtfamfile");
open(BUFF,"$sdrf");
while($line=<BUFF>)
{
	chomp($line);
	@array = split(/\t/,$line);
	@tf = split(/\./,$array[1]);
        @tfa = split('_6_',$tf[0]);
        #$tfam = "$tfa[1] $tfa[1] 0 0 9 -9";

	$hash{$tfa[1]} = $array[0];
	#print $tfa[1]."\n";
}
open(BUFF,"$tfamfile");
while($line = <BUFF>)
{
	chomp($line);
	@array = split(" ",$line);

	if(exists($hash{$array[1]}))
	{
		print WRBUFF $hash{$array[1]}." ".$hash{$array[1]}." $array[2] $array[3] $array[4] $array[5]\n";
	}
	else
	{
		print $line."\n";
	}
}
